const Base = require('./base.js');
const moment = require('moment');
const _ = require('lodash');

module.exports = class extends Base {
    /**
     * list action
     * @return {Promise} []
     */
    async listAction() {
        const list = await this.model('coupon')
            .field('id, user_id, name, send_start_date, send_end_date')
            .where({user_id: this.getLoginUserId()})
            .countSelect();
        console.log('list', list)
        //格式化日期
        list.data = _.map(list.data, (item) => {
            item.send_start_date = moment.unix(item.send_start_date).format('YYYY-MM-DD');
            item.send_end_date = moment.unix(item.send_end_date).format('YYYY-MM-DD');
            
            console.log('item.send_start_date', item.send_start_date)
            console.log('item.send_end_date', item.send_end_date)
            
            return item;
        })

        return this.success(list);
    }
}